﻿using System;
using System.Data;
using System.Collections.Generic;
using Maticsoft.Common;
using dzs.Model;
namespace dzs.BLL
{
	/// <summary>
	/// returnGoods
	/// </summary>
	public partial class returnGoods
	{
		private readonly dzs.DAL.returnGoods dal=new dzs.DAL.returnGoods();
		public returnGoods()
		{}
        #region  Method

        /// <summary>
        /// 得到最大ID
        /// </summary>
        public int GetMaxId()
        {
            return dal.GetMaxId();
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int returnGoodsId)
        {
            return dal.Exists(returnGoodsId);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(dzs.Model.returnGoods model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(dzs.Model.returnGoods model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int returnGoodsId)
        {

            return dal.Delete(returnGoodsId);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string returnGoodsIdlist)
        {
            return dal.DeleteList(returnGoodsIdlist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public dzs.Model.returnGoods GetModel(int returnGoodsId)
        {

            return dal.GetModel(returnGoodsId);
        }

        /// <summary>
        /// 得到一个对象实体，从缓存中
        /// </summary>
        public dzs.Model.returnGoods GetModelByCache(int returnGoodsId)
        {

            string CacheKey = "returnGoodsModel-" + returnGoodsId;
            object objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
            if (objModel == null)
            {
                try
                {
                    objModel = dal.GetModel(returnGoodsId);
                    if (objModel != null)
                    {
                        int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
                        Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
                    }
                }
                catch { }
            }
            return (dzs.Model.returnGoods)objModel;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<dzs.Model.returnGoods> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<dzs.Model.returnGoods> DataTableToList(DataTable dt)
        {
            List<dzs.Model.returnGoods> modelList = new List<dzs.Model.returnGoods>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                dzs.Model.returnGoods model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new dzs.Model.returnGoods();
                    if (dt.Rows[n]["returnGoodsId"] != null && dt.Rows[n]["returnGoodsId"].ToString() != "")
                    {
                        model.returnGoodsId = int.Parse(dt.Rows[n]["returnGoodsId"].ToString());
                    }
                    if (dt.Rows[n]["return_user_name"] != null && dt.Rows[n]["return_user_name"].ToString() != "")
                    {
                        model.return_user_name = dt.Rows[n]["return_user_name"].ToString();
                    }
                    if (dt.Rows[n]["return_user_link"] != null && dt.Rows[n]["return_user_link"].ToString() != "")
                    {
                        model.return_user_link = dt.Rows[n]["return_user_link"].ToString();
                    }
                    if (dt.Rows[n]["user_id"] != null && dt.Rows[n]["user_id"].ToString() != "")
                    {
                        model.user_id = int.Parse(dt.Rows[n]["user_id"].ToString());
                    }
                    if (dt.Rows[n]["proid"] != null && dt.Rows[n]["proid"].ToString() != "")
                    {
                        model.proid = dt.Rows[n]["proid"].ToString();
                    }
                    if (dt.Rows[n]["projectName"] != null && dt.Rows[n]["projectName"].ToString() != "")
                    {
                        model.projectName = dt.Rows[n]["projectName"].ToString();
                    }
                    if (dt.Rows[n]["returnTime"] != null && dt.Rows[n]["returnTime"].ToString() != "")
                    {
                        model.returnTime = DateTime.Parse(dt.Rows[n]["returnTime"].ToString());
                    }
                    if (dt.Rows[n]["material"] != null && dt.Rows[n]["material"].ToString() != "")
                    {
                        model.material = dt.Rows[n]["material"].ToString();
                    }
                    if (dt.Rows[n]["mid"] != null && dt.Rows[n]["mid"].ToString() != "")
                    {
                        model.mid = int.Parse(dt.Rows[n]["mid"].ToString());
                    }
                    if (dt.Rows[n]["inid"] != null && dt.Rows[n]["inid"].ToString() != "")
                    {
                        model.inid = int.Parse(dt.Rows[n]["inid"].ToString());
                    }
                    if (dt.Rows[n]["return_nums"] != null && dt.Rows[n]["return_nums"].ToString() != "")
                    {
                        model.return_nums = decimal.Parse(dt.Rows[n]["return_nums"].ToString());
                    }
                    if (dt.Rows[n]["unit"] != null && dt.Rows[n]["unit"].ToString() != "")
                    {
                        model.unit = dt.Rows[n]["unit"].ToString();
                    }
                    if (dt.Rows[n]["returnNo"] != null && dt.Rows[n]["returnNo"].ToString() != "")
                    {
                        model.returnNo = dt.Rows[n]["returnNo"].ToString();
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            return dal.GetRecordCount(strWhere);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  Method
	}
}

